Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 12, 2026

Implementation Plan for Post Revision Commands

  • Explore repository structure and understand existing patterns
  • Create Post_Revision_Command.php file with two commands:
    • wp post revision restore <post_id> - Restore a revision with the given ID
    • wp post revision diff <from> <to> - Compare/diff two revisions with CLI-friendly colored output
  • Register the command in entity-command.php
  • Add command to composer.json commands list
  • Create Behat feature tests for the new commands
  • Address all code review feedback
  • Fix incomplete test scenario for diff between two revisions
  • Replace HTML diff output with CLI-friendly colored output
  • All code quality checks passing ✓

Commands

wp post revision restore <revision_id>

Restores a post to the specified revision using WordPress's native wp_restore_post_revision().

wp post revision restore 123
# Success: Restored revision 123.

wp post revision diff <from> [<to>] [--field=<field>]

Compares revision content using CLI-friendly colored diff output. Auto-detects parent post when <to> is omitted.

# Compare two revisions
wp post revision diff 123 456

# Compare revision with current post
wp post revision diff 123

# Compare specific fields
wp post revision diff 123 456 --field=post_title

Diff Output

The diff command displays changes with color coding:

  • Red lines with - prefix = Deleted lines
  • Green lines with + prefix = Added lines
  • Default color with prefix = Unchanged lines
  • Yellow header lines = Revision metadata (title, date, ID)

Example output:

--- Original Post (2024-01-01 12:00:00) - ID 123
+++ Modified Post (2024-01-02 13:00:00) - ID 456

  Line 1
- Line 2
+ Line 2 modified
  Line 3

Supports 15 post fields: post_title, post_content, post_excerpt, post_name, post_status, post_type, post_author, post_date, post_date_gmt, post_modified, post_modified_gmt, post_parent, menu_order, comment_status, ping_status.

Implementation

  • src/Post_Revision_Command.php: New command class using Text_Diff class directly with custom CLI renderer
  • entity-command.php: Registers post revision namespace
  • composer.json: Adds command entries for autocompletion
  • phpcs.xml.dist: Excludes new command from prefix rules
  • features/post-revision.feature: 7 test scenarios covering success and error cases
Original prompt

This section details on the original issue you should resolve

<issue_title>wp post revisions</issue_title>
<issue_description>This command is to manage revisions for the specific post.
I think that a large number of people need it for now... 😓

Examples:

Lists all revisions for post_id=221

$ wp post revisions 221 --format=json

Restores revision from 233.

$ wp post revisions 221 --restore=233

Displays diff.

$ wp post revisions 221 --diff=233:255

Or

$ wp post revisions 221 --diff=233

</issue_description>

<agent_instructions>Let's start with two new commands:

  1. wp post revision restore <post_id> - Restore a revision with the given ID
  2. wp post revision diff <from> <to> - Compare/diff two revisions</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@danielbachhuber Restoring and displaying diffs would be pretty interesting. @danielbachhuber Another implementation of revisions https://github.com/trepmal/wp-revisions-cli

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@github-actions github-actions bot added command:post Related to 'post' command command:post-list Related to 'post list' command command:post-meta Related to 'post meta' command command:post-meta-get Related to 'post meta get' command command:post-meta-update Related to 'post meta update' command labels Jan 12, 2026
Copilot AI changed the title [WIP] Add commands for restoring and diffing post revisions Add wp post revision restore and diff commands Jan 12, 2026
Copilot AI requested a review from swissspidy January 12, 2026 12:59
@codecov
Copy link

codecov bot commented Jan 12, 2026

Codecov Report

❌ Patch coverage is 78.65169% with 19 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Post_Revision_Command.php 78.65% 19 Missing ⚠️

📢 Thoughts on this report? Let us know!

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

This comment was marked as resolved.

@swissspidy swissspidy marked this pull request as ready for review January 16, 2026 21:06
@swissspidy swissspidy requested a review from a team as a code owner January 16, 2026 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:post Related to 'post' command command:post-list Related to 'post list' command command:post-meta Related to 'post meta' command command:post-meta-get Related to 'post meta get' command command:post-meta-update Related to 'post meta update' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wp post revisions

2 participants